/**
 * ZHU framework. Copyright 2012-, all rights reserved.
 *
 * $Id: LifecycleConfiguration.java 36 2012-08-31 03:02:52Z zhuxiaopeng $
 * $Revision: 36 $
 * $Date: 2012-08-31 11:02:52 +0800 (五, 2012-08-31) $
 * $Author: zhuxiaopeng $
 */
package zhu.framework.entity.lifecycle;

import java.util.*;
import java.util.concurrent.*;

import zhu.framework.entity.*;

/**
 * <p>
 * </p>
 * 
 * @author $Author: zhuxiaopeng $
 * @version $Revision: 36 $ - $Date: 2012-08-31 11:02:52 +0800 (五, 2012-08-31) $
 */
public class LifecycleConfiguration {

	private static final LifecycleConfiguration instance = new LifecycleConfiguration();

	private LifecycleConfiguration() {

	}

	public static LifecycleConfiguration getInstance() {
		return instance;
	}

	@SuppressWarnings("unchecked")
	synchronized <T extends Entity> Class<Lifecycle<T>> getCachedLifecycleClassFor(final Class<T> entityClass) {
		return (Class<Lifecycle<T>>) lifecycleClassCache.get(entityClass);
	}

	@SuppressWarnings("unchecked")
	synchronized <T extends Entity> Class<Lifecycle<T>> cachedLifecycleClassFor(final Class<T> entityClass, final Class<Lifecycle<T>> implClass) {
		return (Class<Lifecycle<T>>) lifecycleClassCache.put(entityClass, implClass);
	}

	private final Map<Class<? extends Entity>, Class<? extends Lifecycle<?>>> lifecycleClassCache = new ConcurrentHashMap<>();

}
